package compraventa.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import compraventa.excepcion.DAOExcepcion;
import compraventa.negocio.GestionAvisos;

/**
 * Servlet implementation class AvisoInsertarServlet
 */
@WebServlet("/AvisoInsertarServlet")
public class AvisoInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /** 
     * Default constructor. 
     */
    public AvisoInsertarServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String nomaviso = request.getParameter("txtNomAviso");
		String mensaje = request.getParameter("mensajeAviso");
		String fechaini = request.getParameter("txtFechaIni");
		String fechafin = request.getParameter("txtFechaFin");
		String ubicacion = request.getParameter("txtUbicacion");
		
		
		GestionAvisos negocio = new GestionAvisos();
		try {
			negocio.insertar(nomaviso, mensaje, fechaini, fechafin,ubicacion);
			//response.sendRedirect(request.getContextPath()	+ "/scv_principal.jsp");
			request.setAttribute("mensaje", "Grabacion correcta");
			RequestDispatcher rd = request.getRequestDispatcher("bien.jsp");
			rd.forward(request, response);
			
		} catch (DAOExcepcion e) {
			request.setAttribute("error" , e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
